home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Typography Samples / Dave’s Fab Samples ƒ / Left and Right Factors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  2.9 KB  |  109 lines  |  [TEXT/KAHL]

  1. #include <Types.h>
  2. #include <QuickDraw.h>
  3. #include <Fonts.h>
  4. #include <Windows.h>
  5. #include <Menus.h>
  6. #include <SegLoad.h>
  7. #include <Memory.h>
  8. #include <Desk.h>
  9.  
  10. #include "graphics routines.h"
  11. #include "graphics libraries.h"
  12. #include "graphics toolbox.h"
  13.  
  14. #include "layout types.h"
  15. #include "layout routines.h"
  16. #include "layout library.h"
  17.  
  18. #include "SampleInterface.h"
  19.  
  20. short MyStrLen(char *x);
  21. static short MyStrLen(x)
  22. char    *x;
  23.     {
  24.     short c = 0;
  25.     while (*x++) c++;
  26.     return c;
  27.     }    /* MyStrLen */
  28.  
  29. void LeftAndRightFactors(WindowPtr sampleWindow)
  30.     {
  31.     /* Variables */
  32.     char                            *myString = "infinity";
  33.     gxGlyphcode                        glyphArray[20];        /* will be enough... */
  34.     gxGlyphJustificationOverride        glyphJustOverride;
  35.     gxLayoutOffsetState                offsetState;
  36.     gxLayoutOptions                    gxLayoutOptions;
  37.     gxLine                            myLine;
  38.     gxPoint                            myPoint;
  39.     gxShape                            layout;
  40.     short                            len, level = 0;
  41.     gxStyle                            myStyle;
  42.     unsigned short                    firstGlyph, secondGlyph;
  43.     gxViewPort                        aViewPort;
  44.     
  45.     /* Initialization */
  46.     
  47.     myPoint.x = ff(30);
  48.     myPoint.y = ff(50);
  49.     
  50.     aViewPort = GXNewWindowViewPort(sampleWindow);
  51.     SetDefaultViewPort(aViewPort);
  52.     
  53.     len = MyStrLen(myString);
  54.     
  55.     InitializeLayoutOptions(&gxLayoutOptions);
  56.     gxLayoutOptions.width = ff(500);
  57.     gxLayoutOptions.just = 0;
  58.     
  59.     myLine.first.x = myLine.last.x = myPoint.x;
  60.     myLine.first.y = 0;
  61.     myLine.last.y = ff(1000);
  62.     GXDrawLine(&myLine);
  63.     
  64.     myLine.first.x = myLine.last.x = myPoint.x + gxLayoutOptions.width;
  65.     GXDrawLine(&myLine);
  66.     
  67.     myStyle = NewLayoutStyle((char *) "\pHoefler Text", ff(50), 0, nil, nil, 0, nil);
  68.     
  69.     layout = GXNewLayout(
  70.         1, &len, (void *) &myString,
  71.         1, &len, &myStyle,
  72.         1, &len, &level,
  73.         &gxLayoutOptions, &myPoint);
  74.     GXDrawShape(layout);
  75.     
  76.     GXGetLayoutGlyphs(layout, glyphArray, nil, nil, nil, nil, nil, nil);
  77.     GXGetOffsetGlyphs(layout, 0, true, &offsetState, &firstGlyph, &secondGlyph);
  78.     glyphJustOverride.glyph = glyphArray[firstGlyph - 1];
  79.     glyphJustOverride.override.growFlags = gxOverrideLimits;
  80.     glyphJustOverride.override.shrinkFlags = 0;
  81.     glyphJustOverride.override.beforeGrowLimit = fixed1;
  82.     glyphJustOverride.override.afterGrowLimit = 0;
  83.     GXSetStyleRunGlyphJustOverrides(myStyle, 1, &glyphJustOverride);
  84.     
  85.     gxLayoutOptions.just = fract1 / 4;
  86.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  87.     GXMoveShape(layout, 0, ff(75));
  88.     GXDrawShape(layout);
  89.     
  90.     gxLayoutOptions.just = fract1 / 2;
  91.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  92.     GXMoveShape(layout, 0, ff(75));
  93.     GXDrawShape(layout);
  94.     
  95.     gxLayoutOptions.just = 3 * (fract1 / 4);
  96.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  97.     GXMoveShape(layout, 0, ff(75));
  98.     GXDrawShape(layout);
  99.     
  100.     gxLayoutOptions.just = fract1;
  101.     GXSetLayout(layout, 0, nil, nil, 0, nil, nil, 0, nil, nil, &gxLayoutOptions, nil);
  102.     GXMoveShape(layout, 0, ff(75));
  103.     GXDrawShape(layout);
  104.     
  105.     GXDisposeShape(layout);
  106.     GXDisposeStyle(myStyle);
  107.     GXDisposeViewPort(aViewPort);
  108.     }    /* main */
  109.